package com.qiaoba.auth.controller;

import com.qiaoba.api.log.annotation.Log;
import com.qiaoba.api.log.enums.BusinessType;
import com.qiaoba.auth.entity.param.OnlineUserParam;
import com.qiaoba.auth.service.OnlineUserService;
import com.qiaoba.common.base.entity.AjaxResult;
import com.qiaoba.common.base.entity.BasePage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 在线用户 Web层
 *
 * @author ailanyin
 * @date 2023-09-17 21:09:52
 */
@RestController
@RequestMapping("/monitor/online")
@RequiredArgsConstructor
@Tag(name = "2.在线用户管理")
public class OnlineUserController {

    private final OnlineUserService onlineUserService;

    @PreAuthorize("hasAuthority('monitor:online:list')")
    @GetMapping("/list")
    @Operation(summary = "获取列表")
    public BasePage list(Integer pageSize, Integer pageNum, OnlineUserParam param) {
        return onlineUserService.selectPageList(pageNum, pageSize, param);
    }

    @Log(title = "在线用户", businessType = BusinessType.DELETE)
    @PreAuthorize("hasAuthority('monitor:online:forceLogout')")
    @DeleteMapping("/{deviceSn}")
    @Operation(summary = "踢除下线")
    public AjaxResult forceLogout(@PathVariable String deviceSn) {
        onlineUserService.deleteOne(deviceSn, false);
        return AjaxResult.success();
    }
}
